<template>
    <view class="content">
        <home     v-if="currPage=='home'" :prePage="prePage"   ref="home"/>
        <cinema   v-if="currPage=='cinema'" ref="cinema"/>
        <user     v-if="currPage=='user'" ref="user"/>
        <!--底部导航-->
        <tabar :currPage="currPage" @switchPage='switchPage'/>

        <!--获取位置信息-->
        <get-location @getLocationOk="getLocationOk"/>
    </view>

</template>
<script>
import home           from '@/pages/home/home'
import user           from '@/pages/user/user'
import cinema         from '@/pages/cinema/cinema'
import Tabar          from '@/components/tabbar/index'
import getLocation    from '@/components/dialog/getLocation'

export default {
    data(){
        return{
            currPage : 'home',
            prePage  : '',
            onShow   : '',
            avatar   :'',
          //  user  :this.$tools.user(),
        }
    },
    components:{
        home, user,Tabar,cinema,getLocation
    },
    computed:{
    },
    methods:{
        switchPage(page){
            this.currPage = page
        },
        getLocationOk(){
            console.log('获取位置成功后')
            console.log('getLocationOk')
            this.$refs['home'].fetchData();
        }
    },
    onLoad(options){
        if(['home','user','cinema'].includes(options.page)){
            this.switchPage(options.page);
        }
    },
    created(){
        let prePage = this.$tools.prePageRoute();
        if(prePage!==undefined){
            this.prePage = prePage
        }
    },
    onShareAppMessage(options){
        return shareObj;
    },
    onReachBottom(){
        console.log('onReachBottom')
        console.log('当前页面:'+this.currPage)
        let subRefs = this.$refs[this.currPage]
        let {current_page,last_page} = subRefs.data.meta //分页信息
        if(current_page>=last_page){
            console.log('热映或者即将上映noMore')
            subRefs.loadingMoreOptions.loading='noMore' //没有了
        }else{
            //页码+1
            subRefs.current_page++
            subRefs.loadingMoreOptions.loading='loading' //加载中
            if(this.currPage==='home'){
                console.log('热映或者即将上映fetchdata')
                //热映或者即将上映
                subRefs.fetchData(subRefs.type)
            }else{
                console.log('热映或者即将上映 nonono')
                subRefs.fetchData()
            }

        }
    },
}
</script>

<style scoped>

</style>
